<?php

namespace co2\dev\v0_0_0;

class Exception extends \Exception

{
	protected static
		$exceptions=array()
		;
		
	protected
		$_message,
		$_level,
		$_debug,
		$_file,
		$_line,
		$_trace
		;
	
	public function __construct
	(
		$message,
		\stdClass $debug=null,
		$level=0,
		$file=null,
		$line=null,
		array $context=null
	)
	
	{
		parent::__construct($message);
		
		$this->_message=$message;
		$this->_debug=$debug;
		$this->_file=is_null($file)?$this->getFile():$file;
		$this->_line=is_null($line)?$this->getLine():$line;
		$this->_trace=is_null($context)?$this->getTrace():$context;
		$this->_level=$level;
		
		$this->file=$this->_file;
		$this->line=$this->_line;
		
		self::$exceptions[]=(object)array
		(
			'message'	=>	$this->_message,
			'level'		=>	$this->_level,
			'debug'		=>	$this->_debug,
			'file'		=>	$this->_file,
			'line'		=>	$this->_line,
			'trace'		=>	$this->_trace,
			'stack'		=>	$this->getTraceAsString()
		);
	}
	
	public static function
	getException
	()
	
	{
		return end(self::$exceptions);
	}
	
	public static function
	getExceptions
	()
	
	{
		return self::$exceptions;
	}
	
	public function getDebug()
	
	{
		return $this->_debug;
	}
	
	public function getLevel()
	{
		return $this->_level;
	}
	
	public function getContext()
	
	{
		return $this->_trace;
	}
}
